Skip to main content

Message Filtering

Message Filtering using GCP Cloud Pub/Sub

Custom attributes can be used as metadata in the Cloud Pub/Sub messages. Attributes can be text strings or byte strings. You can have at most 10 attributes per message. Attribute keys should not start with goog and should not exceed 256 bytes. Attribute values should not exceed 1024 bytes. The message schema can be represented as follows:

message
{
"data": string,
"attributes": {
string: string,
...
},
"messageId": string,
"publishTime": string,
"orderingKey": string
}

Cloud Pub/Sub message format

A Cloud Pub/Sub message consists of fields with the message data and metadata.

  • The message data
  • An ordering key
  • Attributes with additional metadata

Message filtering Rules

Once the message is received on the Cloud Pub/Sub side, the customer can apply various filters in their Cloud Pub/Sub topic subscriptions. Some Subscription filtering expressions are provided below the table. These filters select the name attribute:

FilterDescription
attributes:nameMessages with the name attribute
NOT attributes:nameMessages without the name attribute
attributes.name = "com"Messages with the name attribute and the value of com
attributes.name != "com"Messages without the name attribute and the value of com
hasPrefix(attributes.name, "co")Messages with the name attribute and a value that starts with co
NOT hasPrefix(attributes.name, "co")Messages without the name attribute and a value that starts with co

For more details, please check the Cloud Pub/Sub documentation.

Using Cloud Pub/Sub Message Filtering with OmniCore

OmniCore allows you to take advantage of GCP Cloud Pub/Sub's Message Filtering feature for both telemetry and state messages. To use this feature, the following criterias must be met:

  • The device must send a valid JSON message for the event or state message.
  • The device message must include a "attributes" field (or key) labeled in lowercase. OmniCore will then map the message to the appropriate Cloud Pub/Sub message format.

image info

The following diagram shows an example of a device message that meets the criteria described above, along with how it appears from the customer's perspective in Cloud Pub/Sub.

image info